package com.framework.modules.job.task.yhbtask;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.framework.entity.tran.TranTransactionInfo;
import com.framework.service.yhbservice.YhbTransactionService;
import com.framework.service.yhbservice.YhbUserTerminalRelationService;
import com.framework.utils.DateUtils;
import com.framework.yhbEntity.user.YhbUserTerminalRelation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 结算用户宝机器的vip状态
 */
@Component("verifyVip")
public class VerifyVip {

    private Logger logger= LoggerFactory.getLogger(getClass());

    @Autowired
    private YhbUserTerminalRelationService yhbUserTerminalRelationService;

    @Autowired
    private YhbTransactionService yhbTransactionService;

    public void verifyVip(){

        logger.debug("------结算用户宝机器的vip状态开始-------");

        //查出需要更改vip的关系列表
        List<YhbUserTerminalRelation> list = yhbUserTerminalRelationService.selectList(new EntityWrapper<YhbUserTerminalRelation>()
                .eq("is_use", 1)
                .eq("is_del", 0)

        );
        //昨天的时间
        Date yesterday = DateUtils.addDateDays(new Date(), -1);
        for (YhbUserTerminalRelation relation :list) {

            List<TranTransactionInfo> lists = yhbTransactionService.selectList(new EntityWrapper<TranTransactionInfo>().eq("sn", relation.getSn())
                    .eq("transaction_date", yesterday)
            );
            for (TranTransactionInfo info:lists) {

                relation.setIsVip(info.getIsVip());
                yhbUserTerminalRelationService.updateRelation(relation);
            }

        }
        logger.debug("------结算用户宝机器的vip状态结束-------");
    }


}



